package data

import (
	"context"
	"helloworld/app/user/service/internal/conf"

	"github.com/go-kratos/kratos/v2/log"
	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

func NewMongo(conf *conf.Data, loggers log.Logger) *mongo.Client {
	log := log.NewHelper(log.With(loggers, "module", "user-service/data/mongo"))
	client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(conf.Mongodb.Addr))

	if err != nil {
		log.Fatalf("failed opening connection to mongo: %v", err)
	}

	return client
}
